package demo1;

/**
 * @Author liangzai
 * @Description:
 */
public class Test {
    public static void main(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("abcdef");
        stringBuilder.reverse();
        System.out.println(stringBuilder);
    }

    public static void main17(String[] args) {

        long start = System.currentTimeMillis();
        StringBuffer sbf = new StringBuffer("");
        for(int i = 0; i < 100000; ++i){
            sbf.append(i);
        }

        long end = System.currentTimeMillis();
        System.out.println(end - start);

        start = System.currentTimeMillis();
        StringBuilder sbd = new StringBuilder();
        for(int i = 0; i < 100000; ++i){
            sbd.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
        start = System.currentTimeMillis();//获取当前系统的时间戳
        String s = "";
        for(int i = 0; i < 100000; ++i){
            //以后不能在循环当中 这样去拼接字符串
            s += i;
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    public static void main16(String[] args) {
        /*String s = "hello";
        s += " world";//s指向了 新的对象  s = s + " world";
        System.out.println(s);//helloworld
        */
        String s = "hello";
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(s);
        stringBuilder.append(" world");
        s = stringBuilder.toString();
        System.out.println(s);
    }



    public static void main15(String[] args) {
        final char[] value = {'a','b','c','d'};
        value[0] = 'g';//修改对象 0 下标内容
        //value = new char[10];//指向新的对象



    }

    public static void main14(String[] args) {
        String str = "abcdef";
        String ret = str.substring(1,3);//[)
        System.out.println(ret);
        System.out.println("======");
        String str2 = "    abcde fefef  f     ";
        System.out.println(str2);
        String ret2 = str2.trim();
        System.out.println(ret2);
    }

    public static void main13(String[] args) {
        String str = "name=zhagnsan&age=10";
        //实现多次分割
        String[] ret = str.split("&");
        //[0]:name=zhagnsan   [1]:age=10
        for(String x : ret) {
            //System.out.println(x);
            String[] s = x.split("=");
            for(String ss : s) {
                System.out.println(ss);
            }
        }
    }
    public static void main12(String[] args) {
        String str = "192\\168\\1\\1";
        //System.out.println(str);
        //正则表达式的分割
        String[] ret = str.split("\\\\");

        for(int i = 0; i < ret.length;i++) {
            System.out.println(ret[i]);
        }
        System.out.println("========================");
        String str2 = "name=zhagnsan&age=10";
        String[] ret2 = str2.split("=|&");
        for(int i = 0; i < ret2.length;i++) {
            System.out.println(ret2[i]);
        }
    }

    public static void main11(String[] args) {
        //String str = "name=zhagnsan&age=10";
        //String str = "hello world hello bit";
        String str = "192.168.1.1";
        //正则表达式的分割
        String[] ret = str.split("\\.");

        for(int i = 0; i < ret.length;i++) {
            System.out.println(ret[i]);
        }

    }

    public static void main10(String[] args) {
        String str = "ababcabcdabcdef";
        //替换所有的老的字符为第2个参数
        String ret = str.replace('a','p');
        System.out.println(ret);
        //可以替换 字符串
        String ret2 = str.replace("ab","ppppp");
        System.out.println(ret2);

        String ret3 = str.replaceAll("ab","uuuu");
        System.out.println(ret3);

        String ret4 = str.replaceFirst("ab","kkk");
        System.out.println(ret4);

        System.out.println(str);
    }

    public static void main9(String[] args) {
        String str = "hello";
        char[] chars = str.toCharArray();
        for (char ch : chars) {
            System.out.println(ch);
        }


        String s = String.format("%d-%d-%d", 2019, 9,14);
        System.out.println(s);
    }

    public static void main8(String[] args) {

        String str = "hello";
        String ret = str.toUpperCase();
        System.out.println(ret);

        System.out.println(str);


        String str2 = "HELLO";
        String ret2 = str2.toLowerCase();
        System.out.println(ret2);

    }

    public static void main7(String[] args) {
        //把整数 转化成 字符串
        String str = String.valueOf(123);
        System.out.println(str);
        //这个过程  你可以理解为 序列化 |||   序列化与反序列化
        String str2 = String.valueOf(new Student("张三",11));
        System.out.println(str2);

        //包装类： 首先是一个类 其次 类中 拥有更多的方法  使用起来 非常的方便
        int a = Integer.parseInt("123");
        //int a1 = Integer.valueOf("123");
        System.out.println(a+12);





    }

    public static void main6(String[] args) {
        String s1 = new String("hello");

        int index3 = s1.lastIndexOf('l');
        System.out.println(index3);
        int index4 = s1.lastIndexOf('l',1);
        System.out.println(index4);
        System.out.println("======");

        //返回字符串对应下标的字符
        char ch = s1.charAt(1);
        System.out.println(ch);

        //返回对应字符出现的下标位置  从头开始一个一个查
        //int index = s1.indexOf('l');
        //从指定位置开始找某个字符出现的位置
        int index = s1.indexOf('l',3);
        System.out.println(index);


        //字符串查找 从一个字符串找另一个字符串
        int index2 = s1.indexOf("llo");
        System.out.println(index2);


    }

    public static void main5(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("Hello");

        System.out.println(s1.equals(s2));
        System.out.println(s1.equalsIgnoreCase(s2));

        System.out.println(s1.compareTo(s2));
        System.out.println(s1.compareToIgnoreCase(s2));


    }
    //判断字符串的大小
    public static void main4(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("hz");

        //s1和s2比较 大小  s1 > s2 返回大于0的数字   s1 < s2 返回 小于0 的数字  否则返回0
        System.out.println(s1.compareTo(s2));



    }
    public static void main3(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("hz");

        System.out.println(s1 == s2);

        System.out.println(s1.equals(s2));//被String重写了


        String s3 = "hello";
        String s4 = "hz";
        System.out.println(s3 == s4);
        System.out.println(s3.equals(s4));

    }

    public static void main2(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("world");
        String s3 = s1;
        System.out.println(s3);

        System.out.println(s1.length());

        String str4 = "";
        System.out.println("输出："+str4);
        System.out.println(str4.length());
        System.out.println(str4.isEmpty());

        String str5 = null;
        System.out.println(str5.isEmpty());

    }



    public static void main1(String[] args) {
        String str = "hello";

        String str2 = new String("world");
        System.out.println(str);
        System.out.println(str2);

        char[] array = {'a','b','c'};
        String str3 = new String(array);
        System.out.println(str3);

    }
}
